package com.koron.plan.web.patrollineplan.bean.dto;

import com.koron.plan.web.patrollineplan.bean.po.PlanLinePatrolCheck;
import com.koron.plan.web.patrollineplan.bean.po.PlanLinePatrolItem;
import com.koron.plan.web.patrollineplan.bean.po.PlanLinePatrolRecord;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.util.Assert;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jzp
 * @since 2022/11/24
 */
@EqualsAndHashCode(callSuper = true)
@Data
@ApiModel(value="线路巡视点", description = "PlanLinePatrolItemDTO")
public class PlanLinePatrolItemDTO extends PlanLinePatrolItem {

    @ApiModelProperty("检查项")
    private List<PlanLinePatrolCheck> checkList;

    @ApiModelProperty("数据记录项")
    private List<PlanLinePatrolRecord> recordList;


    @ApiModelProperty("巡视设备")
    private List<PlanLinePatrolEquipment> equipmentList;

    public void addCheck(PlanLinePatrolCheck planLinePatrolCheck) {
        listNoNullCheck().add(planLinePatrolCheck);
    }

    public void addRecord(PlanLinePatrolRecord PlanLinePatrolRecord) {
        listNoNullRecord().add(PlanLinePatrolRecord);
    }

    public List<PlanLinePatrolCheck> listNoNullCheck() {
        if (checkList == null) {
            checkList = new ArrayList<>();
        }
        return checkList;
    }

    public List<PlanLinePatrolRecord> listNoNullRecord() {
        if (recordList == null) {
            recordList = new ArrayList<>();
        }
        return recordList;
    }

    public void fillPlanId(String planId) {
        Assert.notNull(planId, "计划id不可能为空");
        this.setPlanId(planId);
        listNoNullCheck().forEach(e -> e.setPlanId(planId));
        listNoNullRecord().forEach(e -> e.setPlanId(planId));
    }

    public void fillItemId(String itemId) {
        Assert.notNull(itemId, "巡视点id不可能为空");
        listNoNullCheck().forEach(e -> e.setPatrolPointId(itemId));
        listNoNullRecord().forEach(e -> e.setPatrolPointId(itemId));
    }
}
